<?php
//echo "包含了admin.function.php<br/>";

//获取当前项目的详细信息
function get_thissort($sortid)
{
	$thissort=getdataall('app_sort','sortid',$sortid);
	$thissort['sortupname']=getdataf('sortname','app_sort','sortid',$thissort['sortupid']);
	return $thissort;

}

//获取子项目的id,名称,分数
function get_sortson($sortid){
	$sort_sonid=getdataallfc('sortid',"app_sort","sortupid",$sortid);
	if($sort_sonid)
	{
		foreach ($sort_sonid as $key => $value) {
		$sort_son[$key]['sortid']=$value;
		$sort_son[$key]['sortname']=getdataf('sortname',"app_sort","sortid",$value);
		$sort_son[$key]['sortpoint']=getdataf('sortpoint',"app_sort","sortid",$value);
		}
	}
	if(isset($sort_son))
	{
		return $sort_son;
	}
	else return 0;
}
//创建项目(项目名称、类型、父项目、占分、最大、最小)
function insert_sort($sortname,$sorttype,$sortupid,$sortpoint,$sortmax,$sortmin)
{
	$condition="'".$sortname."',".$sorttype.",".$sortupid.",".$sortpoint.",".$sortmax.",".$sortmin;
	$res=insertdata('app_sort',"sortname,sorttype,sortupid,sortpoint,sortmax,sortmin",$condition);
	return $res;
}
//获取所有小组
function get_group(){
	$groups=array();
	$group=getdataallf('groupid',"app_group");
	foreach ($group as $key => $value) {
		$groups[$value]=getdataf('groupname',"app_group","groupid",$value);
	}
	
	return $groups;
}

//获取小组详细信息
function get_group_xx($groupid){
	$thisgroup='';

	//获取测评人员
	$cpry=getdataallfc("userid","app_user_sup","groupid",$groupid);
	if($cpry){
		foreach ($cpry as $key => $value) {
			$thisgroup[1][$value]=getdataf('username','usertable','userid',$value);
		}
	}
	//获取普通成员
	$ptcy=getdataallfc("userid","app_user","groupid",$groupid);
	if($ptcy){
		foreach ($ptcy as $key => $value) {
			$thisgroup[2][$value]=getdataf('username','usertable','userid',$value);
		}
	}
	//获取项目
	$xm=getdataallfc("sortid","app_sort_group","groupid",$groupid);
	if($xm){
		foreach ($xm as $key => $value) {
			$thisgroup[3][$value]=get_sort_xxname($value);
		}
	}
	return $thisgroup;
}

//创建小组
function insert_group($groupid,$groupname)
{
	$condition="'".$groupid."','".$groupname."'";
	return insertdata('app_group','groupid,groupname',$condition);
}

//获取可添加项目
function get_group_sort(){
	$thesort='';
	//所有最底级项目
	$allsort=getdataallfc("sortid","app_sort","sorttype",1);
	//所有等级选择项目
	$nextallsort=getdataallfc("sortid","app_sort","sorttype",2);
	foreach ($allsort as $key => $value) {
		$sortupid=getdataf("sortupid","app_sort","sortid",$value);
		$sortuptype=getdataf("sorttype","app_sort","sortid",$sortupid);
		//出去等级选择子项
		if($sortuptype!=2){
			$thesort[$value]=get_sort_xxname($value);
		}
	}
	foreach ($nextallsort as $key => $value) {
		$thesort[$value]=get_sort_xxname($value);
	}
	return $thesort;
}

//获取项目的所有父节点,按顺序
function get_sortfather($sortid){
	$father[0]=getdataf("sortupid","app_sort","sortid",$sortid);
	$i=1;
	while ($father[$i-1]!=0) {	
		$father[$i]=getdataf("sortupid","app_sort","sortid",$father[$i-1]);
		$i++;
	}
	return $father;
}
//获取项目详细名字
function get_sort_xxname($sortid){
	$father=get_sortfather($sortid);
	$sortname=getdataf("sortname","app_sort","sortid",$sortid);
	foreach ($father as $key => $value) {
		if($value!=0)
		{
			$sortname=getdataf("sortname","app_sort","sortid",$value)."-".$sortname;
		}
	}
	return $sortname;
}



//获取所有用户
function get_user(){
	$thisuser='';
	$user=getdataallf('userid','usertable');
	foreach ($user as $key => $value) {
		$thisuser[$value]=getdataf('username','usertable','userid',$value);
	}
	return $thisuser;
}


//关联项目
function insert_sort_group($sortid,$groupid)
{
	$condition=$sortid.",'".$groupid."'";
	return insertdata('app_sort_group','sortid,groupid',$condition);
}



//获取所有子项目的数据模型
function sort_model($sortupid)
{
	$i=0;
	$sort[0]=$sortupid;
	$queue[0]=$sortupid;
	$sort[1]="_td";
	$queue[1]="_td";

	while($queue)
	{
		//取出队头
		$thissortid=array_shift($queue);

		if($queue)
		{
			if($queue[0]=='_td')
			{
				$i=1;
				array_shift($queue);
			}
		}
		else
		{
			continue;
		}

		$sonsort=getdataallfc('sortid','app_sort','sortupid',$thissortid);
		if($sonsort)
		{
			foreach ($sonsort as $key => $value) {
				$sorttype=getdataf('sorttype','app_sort','sortid',$value);
				if($sorttype!=1)
				{
					array_push($queue,$value);
				}
				//$sortnumber=sort_number($value);
				//$sortname=getdataf('sortname','app_sort','sortid',$value);
				array_push($sort,$value);
				//echo "<td colspan='".$sortnumber."'>".$sortname."</td>";
			}


		}
		else
		{
		}
		if($i==1)
			{
				array_push($queue,'_td');
				array_push($sort,'_td');
				$i=0;
			}
	}
	return $sort;
}
//读取项目底下子项目的总个数
function sort_number($sortid)
{
	$i=0;
	$sorttype=getdataf('sorttype','app_sort','sortid',$sortid);
	if($sorttype==1)
	{
		$i++;
	}
	else
	{
		
		$sort=getdataallfc('sortid','app_sort','sortupid',$sortid);
		if($sort)
		{
			foreach ($sort as $key => $value) 
			{
				$i=$i+sort_number($value);
			}
		}
		
	}

	return $i;
}





?>